package bos.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import bos.dao.IFunctionDao;
import bos.dao.base.impl.BaseDaoImpl;
import bos.domain.Function;
@Repository
public class FunctionDaoImpl extends BaseDaoImpl<Function> implements IFunctionDao{

	
	/**
	 * 
	 */
	public List<Function> findListByUserid(String userid) {
		String hql="SELECT DISTINCT f FROM Function f LEFT OUTER JOIN f.roles r"+ "LEFT OUTER JOIN r.users u WHERE u.id = ?";
		
		return this.getHibernateTemplate().find(hql, userid);
	}

	@Override
	public List<Function> findAllMenu() {
		String hql="FROM Function f WHERE f.generatemenu='1' ORDER BY f.zindex DESC";
		
		return this.getHibernateTemplate().find(hql);
	}

	@Override
	public List<Function> findMenuByUserid(String id) {
		String hql = "SELECT DISTINCT f FROM Function f LEFT OUTER JOIN f.roles r" +
				" LEFT OUTER JOIN r.users u WHERE u.id = ? AND f.generatemenu = '1' ORDER BY f.zindex DESC ";
		return this.getHibernateTemplate().find(hql, id);
	}

}
